<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Class loadjs
 */
class loadjs extends XX_Controller
{
    /**
     * 临时处理
     * @var array
     */
    public $db_js = array(
        'admin-bar' => 'admin-bar',
    );

    function index()
    {
        $this->output->enable_profiler(FALSE); //关闭调试信息

        $this->load->helper('file'); //fun:read_file
        $loads = $this->input->get_post("load", TRUE);
        $loads = explode(',', $loads);

        $out = ''; //输出

        $dev = ENVIRONMENT == "development" ? '.dev' : ''; //是否为开发环境

        foreach ($loads as $handle) {
            if (!array_key_exists($handle, $this->db_js))
                continue;

            $path = HOMEPATH . '/html/js/' . $handle . $dev . '.js';

            $out .= read_file($path) . "\n";
        }

        $expires_offset = 31536000;
        header('Content-Type: application/x-javascript; charset=UTF-8');
        header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
        header("Cache-Control: public, max-age=$expires_offset");
        echo $out;
    }
}